home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-01-14 | 4.6 KB | 223 lines | [TEXT/MPS ] |
- /* _________________________________________________________________________________________________________ //
- Copyright © 1993 Apple Computer, Inc. All rights reserved.
- Macintosh Developer Technical Support.C++ Macintosh Toolbox Framework.
- Programmer: Kent Sandvik
- Date: 1/5/93
- Revision comments are at the end of this file.
- ---
- TVolume is a simple volume based utility class (provides information about volumes)
- TVolume.cp contains the TVolume member functions.
- _________________________________________________________________________________________________________ */
-
- #ifndef _VOLUME_
- #include "Volume.h"
- #endif
-
- // CONSTRUCTORS & DESTRUCTORS
- #pragma segment Volume
- TVolume::TVolume()
- {
- // Assume we will start with the default boot volume.
- fVRefNum = this->GetBootVRefNum();
- fIndex = 1; // boot block index
- }
-
-
- #pragma segment Volume
- TVolume::TVolume(short refNum)
- {
- // Use specified refNum.
- fVRefNum = refNum;
- }
-
-
- #pragma segment Volume
- TVolume::~TVolume()
- {
- }
-
-
- // MAIN INTERFACE
- #pragma segment Volume
- short TVolume::GetBootVRefNum()
- // Return out the VRefNum of the boot volume.
- {
- short ourVRefNum = 0;
- long ourDirID = 0;
-
- fError = ::FindFolder(kOnSystemDisk, kSystemFolderType, kDontCreateFolder, &ourVRefNum, &ourDirID);
- VASSERT(fError == noErr, ("Problems with FindFolder = %d", fError));
-
- return ourVRefNum;
- }
-
-
- #pragma segment Volume
- long TVolume::GetKFreeSpace()
- // Get amount of free space (Kb) on defined volume.
- {
- if (this->GetHParamBlock())
- return ((fPB.volumeParam.ioVFrBlk * fPB.volumeParam.ioVAlBlkSiz) / 1024);
- else
- return -1;
- }
-
-
- #pragma segment Volume
- long TVolume::GetFileCount()
- // Return amount of files on volume.
- {
- if (this->GetHParamBlock())
- return fPB.volumeParam.ioVFilCnt;
- else
- return -1;
- }
-
-
- #pragma segment Volume
- long TVolume::GetDirCount()
- // Return amount of folders on volume.
- {
- if (this->GetHParamBlock())
- return fPB.volumeParam.ioVDirCnt;
- else
- return -1;
- }
-
-
- #pragma segment Volume
- long TVolume::GetCreationDate()
- // Return creation date of volume.
- {
- if (this->GetHParamBlock())
- return fPB.volumeParam.ioVCrDate;
- else
- return -1;
- }
-
-
- #pragma segment Volume
- short TVolume::GetDriverNumber()
- // Get specified driver number.
- {
- if (this->GetHParamBlock())
- return fPB.volumeParam.ioVDrvInfo;
- else
- return 0;
- }
-
-
- #pragma segment Volume
- Boolean TVolume::GetName(Str255& name)
- // Get name of volume.
- {
-
- fPB.volumeParam.ioNamePtr = (StringPtr)name;
- fPB.volumeParam.ioVRefNum = fVRefNum;
- fPB.volumeParam.ioVolIndex = fIndex;
-
- fError = ::PBHGetVInfoSync(&fPB);
- VASSERT(fError == noErr, ("Problems with PBHGetVInfo = %d", fError));
-
- return (fError == noErr);
- }
-
-
- #pragma segment Volume
- short TVolume::GetNumVolumes()
- // Get the amount of mounted volumes (at this instance).
- {
- short num = 0;
-
- for (this->Reset(); !this->Last(); this->Next())
- num++;
-
- return num;
- }
-
-
- // GET/SET FUNCTIONS
- #pragma segment Volume
- void TVolume::SetVRefNum(const short refNum)
- // Set used VRefNum.
- {
- fVRefNum = refNum;
- }
-
-
- #pragma segment Volume
- short TVolume::GetVRefNum() const
- // Get used VRefNum.
- {
- return fVRefNum;
- }
-
-
- // ITERATORS
- #pragma segment Volume
- void TVolume::Reset()
- // Get back to boot block references.
- {
- fVRefNum = this->GetBootVRefNum(); // boot block VRefNum
- fIndex = 1; // boot block index
- fLast = false; // don't know that yet
- this->Next(); // step once to the right position (boot drive)
- }
-
-
- #pragma segment Volume
- Boolean TVolume::Last()
- // Return boolan if this is the last volume or not.
- {
- return fLast;
- }
-
-
- #pragma segment Volume
- void TVolume::Next()
- // Iterate to next volume mounted.
- {
- if (!fLast)
- {
- fPB.volumeParam.ioNamePtr = NULL;
- fPB.volumeParam.ioVRefNum = fVRefNum;
- fPB.volumeParam.ioVolIndex = fIndex;
-
- fError = ::PBHGetVInfoSync(&fPB);
-
- if (fError != nsvErr) // "No such volume" indicates that we are the end
- {
- fIndex++; // OK, increase the index
- fVRefNum = fPB.volumeParam.ioVRefNum;// keep track of the VRefNum
- }
- else
- fLast = true; // we hit the end, raise the flag
- }
- }
-
-
- // INTERNAL FUNCTIONS
- #pragma segment Volume
- Boolean TVolume::GetHParamBlock()
- // Generate a lookup in a pre-defined param block (used by other member functions).
- {
- fPB.volumeParam.ioNamePtr = NULL;
- fPB.volumeParam.ioVRefNum = fVRefNum;
- fPB.volumeParam.ioVolIndex = 0;
-
- fError = ::PBHGetVInfoSync(&fPB);
- VASSERT(fError == noErr, ("Problems with PBHGetVInfo = %d", fError));
-
- return (fError == noErr);
- }
-
-
- // _________________________________________________________________________________________________________ //
-
-
- /* Change History (most recent last):
- No Init. Date Comment
- 1 khs 1/5/93 New file
- 2 khs 1/7/93 Cleanup
- */
-